<?php
class Mcreatequestion extends CI_Model{

    public function __construct(){
        parent::__construct();        
        $this->load->database();
    }
		
   public function insert_question($data){

         if($this->db->insert("tbl_project_question",$data)){
            $cid = $this->db->insert_id();
            return  $cid;
         }
            
        else
        {
            return 0;
        }
            

    }  


     public function insert_answer($data){

        if($this->db->insert("tbl_project_answer",$data))
            return TRUE;
        else
            return FALSE;


    

    }  

 //--- Lay thong tin 1 record qua id
    function getAllProject(){
        $this->db->select("id,name_project,video_project");
        $this->db->order_by("id desc");
        $query=$this->db->get("tbl_project");


        if($query)
            //tra ve tat ca cac ban ghi    
            return $query->result_array();
        else
            return FALSE;
    }


    function getquestionbyid($id)
    {

        $this->db->select("id,id_project,content");
         $this->db->where('id_project',$id);
        $this->db->order_by("id desc");
        $query=$this->db->get("tbl_project_question");
        if($query)
            //tra ve tat ca cac ban ghi    
            return $query->result_array();
        else
            return FALSE;
    }
    function getanswerbyid($id)
    {
      /*  $this->db->select("id,id_project,content,answer_true");
        $this->db->where('id_question',$id);
        $this->db->order_by("id desc");
        $query=$this->db->get("tbl_project_answer");*/

        $this->db->select('A.id_project,A.id_question,A.content,A.answer_true,Q.content as "ContentQuestion"');
        $this->db->from('tbl_project_answer A');
        $this->db->join('tbl_project_question Q', 'A.id_question= Q.id');
        $this->db->where('A.id_question',$id);

        $query = $this->db->get();

       // var_dump( $this->db->get());
       // die;
        if($query)
            //tra ve tat ca cac ban ghi    
            return $query->result_array();
        else
            return FALSE;
        
    }
/*
/*
function getQuestionByID($id){
        $this->db->select('A.id_project,A.id_question,A.content,A.answer_true,Q.content as "ContentQuestion"');
        $this->db->from('tbl_project_answer A');
        $this->db->join('tbl_project_question Q', 'A.id_question= Q.id');
        $this->db->where("Q.id_project",$id);

        $query = $this->db->get();


        if($query)
             return $query->result_array();
        else
            return FALSE;
    }*/



    public function update_ProjectByID($parram){    	
    	try{         
            $this->db->where('id', $parram["id"]);
    		$this->db->update("tbl_project", $parram);	
			return 0;
    	}catch(Exception $e){
 			throw new Exception();
 			return 1;
    	}
		
    }


}